package org.example.jobs.job;

import cn.hutool.core.collection.CollectionUtil;
import com.google.common.collect.Lists;
import org.example.entity.Test;
import org.example.entity.TestData;
import org.example.service.JobService;
import org.example.service.TestDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

/**
 * @author yangzhenyu
 * @version 1.0
 * @description:
 * @date 2023/4/27 17:17
 */
public class BatchDataRunnable implements Callable<List<Integer>> {
    private static final Logger log = LoggerFactory.getLogger(BatchDataRunnable.class);
    private final JobService jobService;
    private final  List<Test> list;

    public BatchDataRunnable(JobService jobService, List<Test> list) {
        this.list = list;
        this.jobService = jobService;
    }


    @Override
    public List<Integer> call()  {
        try {
            if (CollectionUtil.isNotEmpty(list)){
                 jobService.etl(list);
            }
        }catch (Exception e){
            log.error("处理数据异常",e);
            return list.stream().map(Test::getId).collect(Collectors.toList());
        }
        return Lists.newArrayList();
    }
}
